<template>
    <div class="sign-up-info">
       
        <div class="search-list">
            <el-table :data="signUpInfoList" border :height="oHeight" @selection-change="handleSelectionChange">
                <el-table-column
                align="center"
                type="selection"
                width="55">
            </el-table-column>
                <el-table-column
                        align="center"
                        prop="userName"
                        label="店铺名称"
                        min-width="120"></el-table-column>
                <el-table-column
                        align="center"
                        prop="userPhone"
                        label="店主用户名"
                        min-width="120"></el-table-column>
                <el-table-column
                        align="center"
                        label="所属等级"
                        prop="orderSerialNumber"
                        min-width="120">
                        <template slot-scope="scope">
                            {{storeLevel(scope.row.orderSerialNumber)}}
                        </template>
                </el-table-column>
              
                <el-table-column
                        align="center"
                        prop="groupCategory"
                        label="有效期至"
                        min-width="90">
                         <template slot-scope="scope">
                        <span>{{scope.row.groupCategory | dateFormatter('YYYY-MM-DD ')}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        label="状态"
                        min-width="120">
                        <template slot-scope="scope">
                            <!-- <span>{{scope.row.channel}}</span> -->
                            {{computedCheckStatus(scope.row.signUpTime)}}
                        </template>
                </el-table-column>

            </el-table>
            <div class="bottom">
                
                <div class="btn-group" >
                    <el-button type="primary" @click="delshop">删除店铺</el-button>
                    <el-button type="primary" @click="subshop">提交店铺</el-button>
                    <el-button type="primary" @click="showStoreBox=true">添加店铺</el-button>
                </div>
              
            </div>
        </div>
        

        <store-list :showStoreBox.sync="showStoreBox" @chooseStore="getStoreInfo" :chooseAll="true"></store-list>
    </div>
</template>

<script>
    import {dateFormatter} from "../../../../common/js/util";
    import storeList from "@/components/home/store-list.vue";
	import { resize } from "@/common/js/height.js";
	import Qs from 'qs';
    console.log('storeList',storeList);
	export default {
		data() {
			return {
               
			
               
               
				oHeight: 800,
				searchContent: {
					groupName: '',
					userName: '',
					userPhone: '',
					payStatus: '',
                    signUpChannel: '',
                    addTime: '',
			        employeeName: ''
				},
                signUpInfoList: [],
                addInfoList: [],
                total: 0,
                showStoreBox:false,
                check:[],
                ids:[]
			}
        },
        components: {storeList},
		computed: {
			exportLink() {
				const data = {};
				
				data.form_submit = "1";
				data.curpage = this.searchContent.currentPage;
				data.pagesize = this.searchContent.pageSize;
				data.bg_name = this.searchContent.groupName;
				data.verify_people  = this.searchContent.userName;
                data.member_mobile = this.searchContent.userPhone;
                data.store_name = this.searchContent.store_name;
                data.effective_day = this.searchContent.effective_day;
                
                data.cdkey_state  = this.searchContent.cdkey_state;
				data.state  = this.searchContent.payStatus;
				data.project_class = this.searchContent.signUpChannel;
                data.employee_name = this.searchContent.employeeName;
                if (this.searchContent.addTime) {
					const startAddMS = this.searchContent.addTime[0].getTime();
					const endAddMS = this.searchContent.addTime[1].getTime();
					if (startAddMS == endAddMS) {
						data.verify_start_time  = dateFormatter('YYYY-MM-DD ', startAddMS);
						data.verify_end_time  = dateFormatter('YYYY-MM-DD ', endAddMS + (24 * 60 * 60 - 1) * 1000);
                    } else {
						data.verify_start_time = dateFormatter('YYYY-MM-DD ', this.searchContent.addTime[0]);
						data.verify_end_time  = dateFormatter('YYYY-MM-DD ', this.searchContent.addTime[1]);
                    }
				}
				let domain = document.domain;
				if (domain != 'admin.mycjj.com' && domain != 'admin.chejj.cn') {
					domain = 'admin.chejj.cn'
                }
				return location.protocol + '//' + domain.replace('admin', 'api') + '/admin/platform_coupon/index.php?act=platform_coupon&op=get_ucoupon&' + Qs.stringify(data);
			}
		},
		methods: {
			refund(item) {
				// this.$http.post('/admin/afterSalesGroupBuy/index.php?act=signup&op=returnMoney', {
				// 	id: item.id
                // }).then(res => {
                // 	if (res.code == 1) {
                //         item.payStatus = 3;
                //     } else {
                // 		alert(res.msg);
                //     }
                // })
            },
            getStoreInfo(store){
                // this.signUpInfoList=this.signUpInfoList.concat( store);
                this.addInfoList = store.map(function(item) {
								return {
									id: item.storeId,
									userName: item.storeName,
									userPhone: item.storeUserName,
									orderSerialNumber: item.storeLevel,
									groupName: item.store_end_time*1000,
									signUpTime: item.storeStatus,
									
                                    
								}
							});
                            this.signUpInfoList=this.signUpInfoList.concat( this.addInfoList);
                          
		},
        storeLevel(level){
                switch (level) {
                    case '1':
                        return "默认店铺";
                        break;
                    case '2':
                        return "白金店铺";
                        break;
                        default:
                        return "默认店铺";
                }
            },
            delshop(item) {
                
                for(let i=0;i<this.check.length;i++){
                    for(let j=0;j<this.signUpInfoList.length;j++){
                        if(this.check[i].id==this.signUpInfoList[j].id){
                            this.signUpInfoList.splice(j, 1)

                        }

                }
                   
                    
                }

              
				
            },
            subshop(item) {
                var pc_store_ids = "";
                for(let i=0;i<this.check.length;i++){
                    if (i < this.check.length - 1) {
                        pc_store_ids += this.check[i].id + ",";
             } else {
              pc_store_ids +=this.check[i].id;
                    }
                   
                    
                }
                

                const data = {};
                
				
                data.project_id = this.$route.query.id;
                data.form_submit = "ok";
                data.pc_store_ids = pc_store_ids;
                
				this.$http.post('/admin/platform_coupon/index.php?act=platform_coupon&op=edit_project_store', data).then(res => {
					if (res.code == 1) {
                        this.$parent.tabLists = [
                    {"label": "项目券列表", "name": 'group-management'},
					{"label": "发放列表", "name": 'sign-up-info'},
					{"label": "项目券分类", "name": 'group-category'},
					{"label": "发放导入", "name": 'group-detail'}
			]
                        
                        this.$router.go(-1)
                        // this.$router.push(`/home/operate-panel/project-voucher/group-management.vue`) ;
						// alert(res.msg);
					}
					
					else {
						alert(res.msg);
					}
				})
                
            },
            handleSelectionChange(check){
                this.check = check;
                console.log(check);
			},
            computedCheckStatus(code) {
                
				switch (code*1) {
					case 1:
						return '开启';
					case 3:
						return '已过期';
					case 2:
                        return '关闭';
                    case 4:
						return '已失效';
					case 5:
						return '未激活';
					
                    case 9:
                        return '9';
                    case 11:
                        return '11';
                    case 12:
                        return '22';
                    case 999:
						return '999';
				}
			},
		
			search() {
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleSizeChange(pageSize) {
				this.searchContent.pageSize = pageSize;
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleCurrentChange(page) {
				this.searchContent.currentPage = page;
				this.getListData();
			},
			getListData() {
                const data = {};
                
				
                data.project_id = this.$route.query.id;
                
				this.$http.post('/admin/platform_coupon/index.php?act=platform_coupon&op=edit_project_store', data).then(res => {
					if (res.code == 1) {
						if (res.data && res.data.store_list) {
							this.signUpInfoList = res.data.store_list.map(function(item) {
								return {
									id: item.store_id,
									userName: item.store_name,
									userPhone: item.member_name,
									orderSerialNumber: item.grade_name,
									groupName: item.store_end_time*1000,
									signUpTime: item.store_state,
									
                                    
								}
							});
                            this.total = parseInt(res.data.TotalNum);
                            this.channelList=res.data.class_list;
						} else {
							this.signUpInfoList = [];
							this.total = 0;
						}
					}
					else if (res.code == 2001) {
						this.signUpInfoList = [];
						this.total = 0;
					}
					else {
						alert(res.msg);
					}
				})
			}
		},
		mounted() {
			resize(this)
		},
		created() {
			// if (this.$parent.tabLists[1] && this.$parent.tabLists[1].label == "审核" && this.$parent.tabLists[1].name == "group-detail") {
			// 	this.$parent.tabLists.splice(1, 1);
            // }
            this.$parent.tabLists = [
            {"label": "项目券列表", "name": 'group-management'},
					{"label": "发放列表", "name": 'sign-up-info'},
					{"label": "项目券分类", "name": 'group-category'},
					{"label": "发放导入", "name": 'group-detail'},
				{"label": "店铺编辑", "name": 'group-edit'}
            ]
           
            
            
			this.getListData();
		},
		name: "group-edit"
	}
</script>

<style lang="scss" scoped>
    .sign-up-info {
        .search-content {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            &-input {
                width: 200px;
            }
            .time-range-wrapper {
                .time-range-label {
                    font-size: 14px;
                }
                display: flex;
                align-items: center;
                /deep/.el-range-separator {
                    box-sizing: content-box;
                }
            }
        }
        .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }
    .btn-bottom {
        background: #409EFF;
        color: #fff;
        border: 0;
        font-size: 14px;
        padding: 5px 8px;
        border-radius: 3px;
        display: inline-block;
    }
</style>